#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=1050;
int t,n,m;
int a[3]={1,2,5};
int tmp[N][N];
int ans[N][N];
int main(void){
    scanf("%d",&t);
    while(t--){
        memset(ans,0,sizeof(ans));
        memset(tmp,0,sizeof(tmp));
        scanf("%d%d",&n,&m);
        ans[0][0]=1;
        for(int i=0;i<3;i++){
            for(int j=0;j<=m;j++){
                for(int k=0;k*a[i]+j<=m;k++){
                    for(int t=0;t+k<=n;t++){
                        tmp[j+k*a[i]][k+t]+=ans[j][t];
                    }
                }
            }
            memcpy(ans,tmp,sizeof(ans));
            memset(tmp,0,sizeof(tmp));
        }
        printf("%d\n",ans[m][n]);
    }
    return 0;
}